package com.hsd.znsh.code.sms;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import com.hsd.znsh.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DefaultSmsCodeSender implements SmsCodeSender {

	@Autowired
	private SecurityProperties securityProperties;

	@Autowired
	private SmsSingleSender sender;

	@Override
	public void send(String mobile, String code) {
		SmsSingleSenderResult result = null;
		try {
			String[] params = {code,"1"};
			int templateId=securityProperties.getCode().getSms().getTemplateId();
			String sign=securityProperties.getCode().getSms().getSign();
			result = sender.sendWithParam("86", mobile,templateId,params, sign, "","");
		} catch (HTTPException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.print(result);
	}

}
